home *** CD-ROM | disk | FTP | other *** search
/ Nebula 1 / Nebula One.iso / Financial / Stopwatch2.3 / Source / Preferences.m < prev    next >
Text File  |  1995-06-12  |  2KB  |  107 lines

  1. /*
  2.  * For legal stuff see the file COPYRIGHT
  3.  */
  4. #import "Preferences.h"
  5.  
  6. @implementation Preferences
  7.  
  8. /* Attribute defaults */
  9. #define    DFLT_INVOICE_NUM    "0"
  10. #define DFLT_INVOICE_DIR    "/tmp"
  11. #define DFLT_HIDE_ON_AUTO    "NO"
  12.  
  13. static BOOL
  14. yes( const char *attr )
  15. {
  16.   const char *value = GET_DEFAULT(attr);
  17.  
  18.   return ( value && strcmp( value, "YES") ? YES : NO );
  19. }
  20.  
  21. + initialize
  22. {
  23.   static NXDefaultsVector dflts = {
  24.     { INVOICE_NUM,         DFLT_INVOICE_NUM },
  25.     { INVOICE_DIR,         DFLT_INVOICE_DIR },
  26.     { HIDE_ON_AUTO,         DFLT_HIDE_ON_AUTO },
  27.     { NULL }
  28.   };
  29.  
  30.   NXRegisterDefaults( OWNER, dflts ) ;
  31.   return self ;
  32. }
  33.  
  34. /*
  35.  * Allow only one preferences object for this app
  36.  */
  37. + new
  38. {
  39.   static id prefs;
  40.  
  41.   if ( ! prefs ) {
  42.     prefs = [[Preferences alloc] init];
  43.     [NXApp loadNibSection:"Preferences.nib" owner:prefs withNames:NO];
  44.     [prefs revert:nil];
  45.   }
  46.     
  47.   return prefs;
  48. }
  49.  
  50. /*
  51.  * Called by the controller to see if we should hide ourselves.
  52.  * Return YES if we were autolaunched and the user said to hide.
  53.  */
  54. - (BOOL)hideOnAutoLaunch
  55. {
  56.   
  57.   return( yes( "NXAutoLaunch" ) && yes(HIDE_ON_AUTO) );
  58. }
  59.  
  60. - display
  61. {
  62.   [invoiceNumberText selectText:nil];
  63.   [window makeKeyAndOrderFront:self];
  64.   return self;
  65. }
  66.  
  67. - chooseDir:sender
  68. {
  69.   OpenPanel *panel = [OpenPanel new];
  70.   int result;
  71.  
  72.   [panel chooseDirectories:YES];
  73.   result = [panel runModalForDirectory:NXHomeDirectory() file:""];
  74.   if ( result != NX_RUNABORTED )
  75.     [directoryText setStringValue:[panel filename]];
  76.   return self;
  77. }
  78.  
  79. - ok:sender
  80. {
  81.   PUT_DEFAULT( INVOICE_NUM, [invoiceNumberText stringValue] ) ;
  82.   PUT_DEFAULT( INVOICE_DIR, [directoryText stringValue] ) ;
  83.   PUT_DEFAULT( HIDE_ON_AUTO,[hideButton state] ? "YES" : "NO" ) ;
  84.   [window close];
  85.   return self;
  86. }
  87.  
  88. - revert:sender
  89. {
  90.   NXUpdateDefaults() ;        /* reload the table from the database */
  91.  
  92.   [invoiceNumberText setStringValue:GET_DEFAULT(INVOICE_NUM)];
  93.   [directoryText     setStringValue:GET_DEFAULT(INVOICE_DIR)];
  94.   [hideButton        setState:yes(HIDE_ON_AUTO)];
  95.   return self;
  96. }
  97.  
  98. - reset:sender
  99. {
  100.   [invoiceNumberText setStringValue:DFLT_INVOICE_NUM];
  101.   [directoryText     setStringValue:DFLT_INVOICE_DIR];
  102.   [hideButton        setState:yes(DFLT_HIDE_ON_AUTO)];
  103.   return self;
  104. }
  105.  
  106. @end
  107.